function init_invreceived() {
	if(invr_yui_table_instance == null){
		//For now, create and show yui table.
		create_invreceived_yui_table();
	}
	
	clear_invreceived_yui_table();
 
	var dwrCallMetaData = {
			callback : success_fetchinvoicerecd,
			exceptionHandler : exception_generic_handler,
			timeout : 100000,
			errorHandler : exception_generic_handler
		};
	
	if(usr_comp_cache == null) {setTimeout(init_invreceived, 1000); return;}
	
	DWR_Invoice.fetchInvoicesReceived(usrcompany_uid,dwrCallMetaData);
}

var inv_recdcache = null;

function success_fetchinvoicerecd(dwrresp){
	clear_invreceived_yui_table();
	inv_recdcache = null;
	if(dwrresp.objRespOrError != null && dwrresp.objRespOrError.length > 0){
		inv_recdcache = dwrresp.objRespOrError;
		invr_yui_table_instance.addRows(dwrresp.objRespOrError);
	}
}

var invr_yui_table_instance = null;
function create_invreceived_yui_table() {
	if(invr_yui_table_instance == null){
	var invrcolumnDefs = [{
		key : "selectThis",
		label : "Select",
		formatter : "radio",
		sortable : false,hidden:true
	},
   {
		key : "invoiceNumber",
		label : "Invoice#",
		sortable : true,formatter : "hlinkFormatter",maxAutoWidth:"85"
	}, {
		key : "supplierNameText",
		label : "Supplier",
		sortable : true
	}, {
		key : "invoiceSubmittedDate",
		label : "Date",
		formatter: "date",
		sortable : true,maxAutoWidth:"55"
	} , {
		key : "purchaseOrderNumber",
		label : "PO#"
	}, {
		key : "totalInvoiceAmount",
		label : "Amount",
		formatter: "currency",maxAutoWidth:"38"
	} ];

	var invrDataSource = new YAHOO.util.DataSource();
	invrDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	 var oConfigs = {
             paginator: new YAHOO.widget.Paginator({
                 rowsPerPage: 2
                 
             }),
             initialRequest: "results=504",
             width: "600px",
             // we'll leave the actual loading for later
 			initialLoad:true, 
 				
 			// This function links the master to the nested tables
 			generateNestedRequest: function (record) {
 				return lineItemData;

 			}
     };
	 /*por_yui_table_instance = new YAHOO.widget.NestedDataTable(
				'poreceived_yui_table', 
				porcolumnDefs,
				porDataSource,
				lineItemReadOnlycolumnDefs,
				lineItemDataSource,
				oConfigs);*/
	 invr_yui_table_instance = new YAHOO.widget.DataTable("invreceived_yui_table",invrcolumnDefs,invrDataSource,oConfigs);
	 invr_yui_table_instance.set("selectionMode", "single");
	 invr_yui_table_instance.subscribe("rowClickEvent",
			 invr_yui_table_instance.onEventSelectRow);
	//por_yui_table_instance.subscribe("nestedToggleEvent",additemsr_tonested); 
	}

}

function clear_invreceived_yui_table() {
	if (invr_yui_table_instance != null && invr_yui_table_instance.getRecordSet() != null && invr_yui_table_instance.getRecordSet().getLength() > 0) {
		var length = invr_yui_table_instance.getRecordSet().getLength();
		if (length > 0) {
			invr_yui_table_instance.deleteRows(0, length);
		}
	}
}